﻿<?php require_once('Connections/edireal.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
if(!function_exists("InsertStringOffer")){
function InsertStringOffer ($TheId, $TheTop, $TheCat, $TheTown, $TheRegion, $theAdres, $ThePrice, $TheTprice, $TheFull_Info, $TheKomnat, $TheEtaznost, $TheBalkon, $TheLodz, $ThePlosad, $ThePl_Live, $TheCompanu_Name, $TheCompany_Phone)
{
	 $insertSQL = sprintf("INSERT INTO offer (id, top, cat, town, region, adress, price, tprice, full_info, komnat, etaznost, balkon, lodz, ploshad, pl_live, company_name, company_phone) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($TheId, "int"),
                       GetSQLValueString($TheTop, "text"),
                       GetSQLValueString($TheCat, "text"),
                       GetSQLValueString($TheTown, "text"),
                       GetSQLValueString($TheRegion, "text"),
                       GetSQLValueString($theAdres, "text"),
                       GetSQLValueString($ThePrice, "int"),
                       GetSQLValueString($TheTprice, "text"),
                       GetSQLValueString($TheFull_Info, "text"),
                       GetSQLValueString($TheKomnat, "int"),
                       GetSQLValueString($TheEtaznost, "int"),
                       GetSQLValueString($TheBalkon, "text"),
                       GetSQLValueString($TheLodz, "text"),
                       GetSQLValueString($ThePlosad, "double"),
                       GetSQLValueString($ThePl_Live, "double"),
                       GetSQLValueString($TheCompanu_Name, "text"),
                       GetSQLValueString($TheCompany_Phone, "text"));
					   //echo $insertSQL;
					   echo "id равен:=";echo $TheId; echo $item->id;

  mysql_select_db($database_edireal, $edireal);
  $Result1 = mysql_query($insertSQL, $edireal) or die(mysql_error());
}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>парсинг и отчет</title>
</head>

<body>
<?php 
  $deleteSQL = "TRUNCATE TABLE offer";
  mysql_select_db($database_edireal, $edireal);
  $Result1 = mysql_query($deleteSQL, $edireal) or die(mysql_error());
 ?>
<p>
  <?php
$url = '8012.php';       //адрес XML документа
 
$xml= simplexml_load_file($url);       //Интерпретирует XML-документ в объект

foreach ($xml as $item){
	echo $item->id;
	InsertStringOffer($item->id,$item->top,$item->cat,$item->town,$item->region,$item->adres,$item->price,$item->tprice,$item->full_info,$item->komnat,$item->etaznost,$item->balkon,$item->lodz,$item->ploshad,$item->pl_live,$item->company_name,$item->company_phone);
	}
//Выводим XML на печать
/*
$i;
$i=0;
foreach ($xml as $item) {
        echo $item->id;	      
        echo $item->top;        
        echo $item->cat;       
        echo $item->town;       
        echo $item->region;
		echo $item->adres;
		echo $item->price;
		echo $item->tprice;
		echo $item->full_info;
		echo $item->komnat;
		echo $item->etaznost;
		echo $item->balkon;
		echo $item->lodz;
		echo $item->ploshad;
		echo $item->pl_live;
		echo $item->company_name;
		echo $item->company_phone;	
		echo "<p>";
		echo "i="; echo $i;
		$i++;	
		
}
*/
?>
<form id="form1" name="form1" method="POST" action="">
  <input type="submit" name="button" id="button" value="Отправить" />
  <input type="hidden" name="id" id="hiddenField" />
  <input type="hidden" name="top" id="hiddenField2" />
  <input type="hidden" name="cat" id="hiddenField3" />
  <input type="hidden" name="town" id="hiddenField4" />
  <input type="hidden" name="region" id="hiddenField5" />
  <input type="hidden" name="adres" id="hiddenField6" />
  <input type="hidden" name="price" id="hiddenField7" />
  <input type="hidden" name="tprice" id="hiddenField8" />
  <input type="hidden" name="full_info" id="hiddenField9" />
  <input type="hidden" name="komnat" id="hiddenField10" />
  <input type="hidden" name="etaznost" id="hiddenField11" />
  <input type="hidden" name="balkon" id="hiddenField12" />
  <input type="hidden" name="lodz" id="hiddenField13" />
  <input type="hidden" name="plosad" id="hiddenField14" />
  <input type="hidden" name="pl_live" id="hiddenField15" />
  <input type="hidden" name="company_name" id="hiddenField16" />
  <input type="hidden" name="company_phone" id="hiddenField17" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>